package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 针对单一方法的降级处理
 * @author timiv
 */
@RestController
public class OrderController {

    @Autowired
    private PaymentHystrixService paymentService;
    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String payment_ok(@PathVariable("id") Integer id){
        return paymentService.payment_ok(id);
    };


    @GetMapping("/consumer/payment/hystrix/timeOut/{id}")
    @HystrixCommand(fallbackMethod = "paymentInfo_handle",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    })
    public String payment_timeOut(@PathVariable("id") Integer id){
        return paymentService.payment_timeOut(id);
    };

    public String paymentInfo_handle(Integer id){
        return "我是客户端80，调用服务端超时或者自生出现异常，/(ㄒoㄒ)/~~";
    }
}
